<template>
  <div class="f2bpm-page-layout">
    <div id="layui_container" class="layui-container" style="width: 100%; margin: 0px; padding: 0px; ">
      <div style="padding:5px;line-height:30px;">
        <i class="fa fa-edit " >请在空白处手写签名 </i> 
		<el-button @click="reset"  style="float: right;margin-right: 10px;" type="text"  size="mini" >
		  <i class="fa fa-undo"></i>重写
		</el-button>
      </div>
      <div id="signature" style="border: 1px solid #ccc; min-height:20rem; "></div>
    </div>
  </div>
</template>
<script type="text/javascript">
  window.$signature = null;
  export default {
    created() {
      var that = this;
      var signId = Object.toQueryString("signId");
      var linkType = Object.toQueryString("linkType") || "";
      var linkEntityId = Object.toQueryString("linkEntityId") || "";
      var creatorId = Object.toQueryString("creatorId") || "";
	  var isreSign = Object.toQueryString("isreSign") || 0;
	  that.isreSign=isreSign;
      that.signId = signId;
      that.creatorId = creatorId;
      that.linkType = linkType;
      that.linkEntityId = linkEntityId;
    }
    , mounted() {
      $signature = $("#signature").jSignature({
        height: '28rem',
        width: '100%',
        'UndoButton': true
      });
      window.myvm = this;
    }
    , data() {
      return {
		isreSign:0,
        creatorId: "",
        signId: "",
        linkType: "",
        linkEntityId: ""
      };
    },
    methods: {
      submitSave() {
        var that=this;
        var data = $signature.jSignature('getData', 'default');
        var data = Object.toAjaxJson("/workflow/public/", "handSignSave", {
          "imgdata": data,
          "signId": that.signId,
          "linkType": that.linkType,
          "linkEntityId": that.linkEntityId,
          "creatorId": that.creatorId
        });
        if (data.success) {
         return  true;
        } else {
          FUI.Window.showMsg(data.msg);
        }
		return  false;
      }
      , reset() {
        $signature.jSignature('reset')
      }
	  ,show() {
	    var that = this;
	    var data = Object.toAjaxJson("/workflow/public/", "getHandSignData", {
	      "signId": that.signId
	    });
	    $("#LoadingDiv").hide();
	    if (data.success == true && data.data != "") {
	      $("#title_div").html("请点击确认您的签名 <span  class=\"btn btn-minier btn-light cur \" onclick='reSign();'>重新签名</span>");
	      $("#QrCodeImgPath").hide();
	      var img = new Image();
	      img.src = data.data;
	      $(img).attr("width", "350");
	      $('#signimg').html($(img).prop("outerHTML"));
	      clearInterval(timer1);
	    } else {
	      console.info(data.msg);
	    }
	    if (data.data == "") {
	      $("#title_div").html("请点击确认您的签名 <span  class=\"btn btn-minier btn-light cur \" onclick='reSign();'>重新签名</span>");
	    }
	  }
      , getResult() {
		  var that=this;
		  if(!that.submitSave()){
			   return false;
		  }
          return this.signId;
      }
    }
   
  }
  window.getResult = function () {
    var result =myvm.getResult();
    return result;
  }

</script>